﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace TestConsole
{
    public class InfoSaver
    {
        public static string TempFileName = "temp.json";
        static JsonSerializerSettings setting;
        static InfoSaver()
        {
            setting = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
                TypeNameHandling = TypeNameHandling.Auto
            };
        }
        public void SaveToFile(string fileName, object list)
        {
            File.WriteAllText(fileName, JsonConvert.SerializeObject(list, setting));
        }

        public T Get<T>(string fileName)
        {
            if (File.Exists(fileName))
            {
                return JsonConvert.DeserializeObject<T>(File.ReadAllText(fileName), setting);
            }
            return default(T);
        }
    }
}
